package com.pgeg.enchantment;

import com.pgeg.api.mana.IManaHandler;
import com.pgeg.listener.StatusEffectListener;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;

public class VampireEnchantment extends Enchantment {

    public VampireEnchantment() {
        super(Rarity.UNCOMMON, EnchantmentTarget.WEAPON, new EquipmentSlot[] {EquipmentSlot.MAINHAND});
    }

    @Override
    public int getMinPower(int level) {
        return 1;
    }

    @Override
    public int getMaxLevel() {
        return 3;
    }

    @Override
    public void onTargetDamaged(LivingEntity user, Entity target, int level) {
        if (((IManaHandler) user).getMana() > 0) {
            if (user instanceof PlayerEntity) {
                user.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 20 * 2 * level, level - 1));
                user.addStatusEffect(new StatusEffectInstance(StatusEffectListener.MANA_REDUCTION, 4 * 2 * level, level - 1));
            }
        }
        super.onTargetDamaged(user, target, level);
    }
}
